package com.glory.brepda.activity.mfg;

import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.glory.brepda.R;
import com.glory.brepda.adapter.LotMantissaAdapter;
import com.glory.brepda.base.BaseActivity;
import com.glory.brepda.callback.CustomDialogEntityCallBack;
import com.glory.brepda.entity.LotInfoEntity;
import com.glory.brepda.entity.response.BaseResponseBean;
import com.glory.brepda.utils.NetUtils;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import com.lzy.okgo.model.Response;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_EntityCallBack;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_StaticMembers;
import com.pda.platform.ui.ui_pdaplatform.view.FreeUI_ClearEditText;

import butterknife.BindView;

public class QueryEndLotActivity extends BaseActivity implements View.OnClickListener {

    @BindView(R.id.llMain)
    LinearLayout llMain;
    @BindView(R.id.etLotID)
    FreeUI_ClearEditText etLotID;
    @BindView(R.id.tvTitle)
    TextView tvTitle;
    @BindView(R.id.tvBaseSubmit)
    TextView tvBaseSubmit;
    @BindView(R.id.rvLotList)
    RecyclerView rvLotList;
    @BindView(R.id.tvMainQTY)
    TextView tvMainQTY;
    @BindView(R.id.tvJudge1)
    TextView tvJudge1;
    @BindView(R.id.tvOpenbigMAX)
    TextView tvOpenbigMAX;
    @BindView(R.id.tvOpenbigMIN)
    TextView tvOpenbigMIN;
    private LotInfoEntity.LotBean lotInfoEntity;
    private LotMantissaAdapter mLotMantissaAdapter;
    @Override
    protected int getLayoutResId() {
        return R.layout.activity_querymantissa;
    }

    @Override
    protected void initView() {
        setMainLayout(llMain);
        String title = getIntent().getStringExtra(FreeApi_StaticMembers.SHOW_PLUGIN_KEY);
        tvTitle.setText(title);
        tvBaseSubmit.setVisibility(View.GONE);

        mLotMantissaAdapter = new LotMantissaAdapter(null);
        mLotMantissaAdapter.openLoadAnimation(BaseQuickAdapter.ALPHAIN);
        mLotMantissaAdapter.isFirstOnly(true);
        initRecyclerView(rvLotList, this);
        rvLotList.setAdapter(mLotMantissaAdapter);
    }

    @Override
    protected void initData() {
        initEdit(etLotID, s -> {
            FreeUI_EntityCallBack<BaseResponseBean<LotInfoEntity>> callBack = new CustomDialogEntityCallBack<BaseResponseBean<LotInfoEntity>>
                    ("正在查询LOT信息", new TypeToken<BaseResponseBean<LotInfoEntity>>() {
                    }.getType(), getSupportFragmentManager(), QueryEndLotActivity.this) {

                @Override
                public void onSuccess(Response<BaseResponseBean<LotInfoEntity>> response) {
                    super.onSuccess(response);
                    if (response.body().isSuccess(QueryEndLotActivity.this, true, getSupportFragmentManager())) {
                        mLotMantissaAdapter.setNewData(response.body().getResponse().getBody().getLOTLIST());
                        for (LotInfoEntity.LotBean data:response.body().getResponse().getBody().getLOTLIST()){
                            if (s.equals(data.getLOTID())){
                                lotInfoEntity = data;
                            }
                        }
                        if (lotInfoEntity != null){
                            tvMainQTY.setText(lotInfoEntity.getMAINQTY());
                            tvJudge1.setText(lotInfoEntity.getJUDGE1());
                            tvOpenbigMAX.setText(lotInfoEntity.getOPENBIGMAX());
                            tvOpenbigMIN.setText(lotInfoEntity.getOPENBIGMIN());
                        }
                    }

                }

                @Override
                public void onError(Response<BaseResponseBean<LotInfoEntity>> response) {
                    super.onError(response);
                    loadError(response.getException(), "LOTQUERY");
                }
            };

            JsonObject map = new JsonObject();
            map.addProperty("ACTIONTYPE", "ENDLOTSBYLOTID");
            map.addProperty("LOTID", s);
            NetUtils.requestPostNet("IF.LOTQUERY", "Common", QueryEndLotActivity.this, map, callBack);
        });

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.tvBaseSubmit:

                break;
        }
    }
}
